
<!DOCTYPE html>

<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>
    <script>
        $(function () {
            //绑定查看文章按钮点击事件
            $(".lookBtn").click(function () {
                //拿到json数据，回显到模态框
                // var json = $(this).data("json");
                // if (json) {
                //     $("#contentModal .modal-body").html(json.content);
                // }
                //发送ajax请求获取文本内容
                $.get("/travel/getContentById.do", {id: $(this).data("id")}, function (data) {
                    $("#contentModal .modal-body").html(data.content);
                });
                //显示模态框
                $("#contentModal").modal("show");
            });
            //绑定更改发布状态按钮事件
            $(".changeStateBtn").click(function () {
                $.get("/travel/changeState.do",{id: $(this).data("id"),state:$(this).data("state")},function (data) {
                    if(data.success) {
                        reload();
                    }
                });
            });
            //推荐按钮绑定模态框
            $(".commendBtn").click(function () {
                //清空原来的值
                $("#editForm input").val("");
                //清空封面回显，避免出现为空时的错误？\\可以不用，因为下面已经相当于重新设置了
                //$("#coverUrl").attr("src","");
                //拿到json数据回显到模态框
                var json=$(this).data("json");

                if(json) {
                    $("#editForm input[name='travel.id']").val(json.id);
                    $("#editForm input[name='title']").val(json.title);
                    $("#editForm input[name='coverUrl']").val(json.coverUrl);
                    $("#coverUrl").attr("src",json.coverUrl);

                }

                //显示模态框
                $("#inputModal").modal("show");
            });
            //保存按钮绑定点击事件
            $(".btn-submit").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if (data.success) {
                        reload();
                    }
                })
            });

            //设置日历
            $("#editForm input[name='schedule']").click(function () {
                WdatePicker({
                    readOnly: true,
                    minDate:new Date()
                });
            });
        });
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#--设置作用于贡献数据，以回显菜单栏信息-->
            <#assign menu="releaseList"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">已发布游记列表</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travel/releaseList.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>地点</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    <th>状态</th>
                    <th></th>
                    <th></th>
                    <th></th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index+1}</td>
                       <td>${entity.title}</td>
                       <td><img src="${entity.coverUrl}" alt="图裂" style="width: 35px"></td>
                       <td>${(entity.place.name)!}</td>
                       <td>${(entity.author.nickName)!}</td>
                        <td>${entity.releaseTime?string("yyyy-MM-dd")}</td>
                       <td>${entity.stateName}</td>
                        <td>
                            <a class="changeStateBtn" data-id="${entity.id}" data-state="1" role="button">取消发布</a>
                        </td>
                        <td>
                            <a class="lookBtn" role="button" data-id="${entity.id}">查看文章</a>
                        </td>
                        <td>
                            <a  class="commendBtn" data-json='${entity.json}' role="button">推荐</a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#--分页-->
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<#--推荐模态框-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">新增游记推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="travel.id">
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title"
                                   placeholder="请输入标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="subTitle" name="subTitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" alt="图裂" style="width: 100%">
                            <input type="file"  name="file">
                            <input type="hidden" class="form-control"  name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="schedule" name="schedule">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-4 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select id="auditState" class="form-control" autocomplete="off" name="type" >
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<#--查看文章模态框-->
<div class="modal fade" id="contentModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">文章内容</h4>
            </div>
            <div class="modal-body">
            </div>
            <div class="modal-footer">
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
<style>
    /*给模态框中的图片设置样式*/
    #contentModal img{
        width: 100%;
    }
</style>
</html>